Ext.define('Triends.view.Settings', {
	extend: 'Ext.Panel',
	xtype: 'settingslist',
	id: 'settingslist',
	config: {
	   	items: [{
	   		xtype: 'titlebar',
 			ui: 'light',
 			docked: 'top',
 			style: 'margin-bottom:20px',
 			title: 'Information'
	   	},
	   	{
	   		xtype: 'list',
	   		scrollable: false,
			style: 'background:white',
	   		pressedCls: "x-item-selected",
	   		margin:15,
			selectedCls: "",
			pressedDelay: 50,
 			store: {
	 			fields: ["name", "number"],
	 			data: [
	 				{name: "<table width='100%' cellpadding='0'>"+
								"<tr>" +
									"<td valign='center' style='word-break:break-all'><font size='3'><b>버전정보</b></font></td>" +
									"<td width='30' align='right' style='word-break:break-all;padding-top:5px'><img src='resource/images/arrow2.png' width='15px' height='25px'></td>" +
								 "</tr>" +
							"</table>", id: 'versionpage'},
	 				{name: "<table width='100%' cellpadding='0'>"+
								"<tr>" +
									"<td valign='center' style='word-break:break-all'><font size='3'><b>공지사항</b></font></td>" +
									"<td width='30' align='right' style='word-break:break-all;padding-top:5px'><img src='resource/images/arrow2.png' width='15px' height='25px'></td>" +
								 "</tr>" +
							"</table>", id: 'noticelist'},
	 				{name: "<table width='100%' cellpadding='0'>"+
								"<tr>" +
									"<td valign='center' style='word-break:break-all'><font size='3'><b>도움말</b></font></td>" +
									"<td width='30' align='right' style='word-break:break-all;padding-top:5px'><img src='resource/images/arrow2.png' width='15px' height='25px'></td>" +
								 "</tr>" +
							"</table>", id: 'helppage'},
	 				{name: "<table width='100%' cellpadding='0'>"+
								"<tr>" +
									"<td valign='center' style='word-break:break-all'><font size='3'><b>문의 / 건의</b></font></td>" +
									"<td width='30' align='right' style='word-break:break-all;padding-top:5px'><img src='resource/images/arrow2.png' width='15px' height='25px'></td>" +
								 "</tr>" +
							"</table>", id: 'questionpage'},
					{name: "<table width='100%' cellpadding='0'>"+
								"<tr>" +
									"<td valign='center' style='word-break:break-all'><font size='3'><b>Push설정</b></font></td>" +
									"<td width='30' align='right' style='word-break:break-all;padding-top:5px'><img src='resource/images/arrow2.png' width='15px' height='25px'></td>" +
								 "</tr>" +
							"</table>", id: 'pushpage'}]
 			},
		   	itemTpl: '{name}',
		   	listeners: {
		   		itemtap: function(list, index, target, model, e, eOpts) {
		   			if (model.data.id == 'noticelist') {
		   				var noticestore = Ext.getStore('noticestore');
		   				noticestore.load({
		   					callback: function() {
		   						Triends.app.getHistory().add(Ext.create('Ext.app.Action', {
	            					url: 'mainpage/settings/'+model.data.id
		        				}));
		   					}
		   				})
		   			} else if (model.data.id == 'pushpage') {
		   				var UserStore = Ext.getStore('UserStore');
			    		var userid = UserStore.getAt(0).data.ID;

			    		Ext.data.JsonP.request({
				   			url: 'http://itscreater.cafe24.com/Triends/gcmcheck.jsp',
				   			params: {
				   				id: userid,
				   				device: 0
				   			},
				   			callbackKey: 'callback',
				   			success: function(result) {
				   				if (result.push == 1) {
				   					Ext.getCmp('pushnoti').setChecked(true);
				   				} else if (result.push == 0){
				   					Ext.getCmp('pushnoti').setChecked(false);
				   					Ext.getCmp('vibratenoti').setChecked(false);
				   				}
				   				
				   				if (result.vibrate == 1) {
				   					Ext.getCmp('vibratenoti').setChecked(true);
				   					Ext.getCmp('pushnoti').setChecked(true);
				   				} else if (result.vibrate == 0) {
				   					Ext.getCmp('vibratenoti').setChecked(false);
				   				}
				   				
				   				Triends.app.getHistory().add(Ext.create('Ext.app.Action', {
	            					url: 'mainpage/settings/'+model.data.id
		        				}));
				   			}
						});		   			
		   			} else {
		   				Triends.app.getHistory().add(Ext.create('Ext.app.Action', {
	            					url: 'mainpage/settings/'+model.data.id
		        				}));
		   			}
			    	
		   		}
		   	}
	   	}]
	}
});

